from matplotlib import pyplot as plt

# DataFrame版本
def plot_stability_curves(results_df):
    """
        绘制参数-稳态均值曲线
        :param results_df: run_multiple_simulations的输出结果
        """
    plt.figure(figsize=(10, 6))

    # 计算横坐标：mu_H / lambda
    x_values = results_df['mu_H'] / results_df['lambda_L']

    # 设置种群颜色和标签
    populations = ['LF', 'LC', 'HF', 'HC']
    colors = ['#274753', '#299d8f', '#e7c66b', '#e66d50']
    labels = ['Low-Fat (LF)', 'Low-Carb (LC)', 'High-Fat (HF)', 'High-Carb (HC)']

    # 绘制曲线
    for pop, color, label in zip(populations, colors, labels):
        plt.plot(x_values,
                 results_df[f'avg_{pop}'],
                 'o-',
                 label=label,
                 color=color,
                 markersize=8,
                 linewidth=2,
                 markeredgecolor='white',  # 增加白色描边提升辨识度
                 markeredgewidth=1)

    # 图表装饰
    plt.xlabel(r'$\mu_H / \lambda$', fontsize=14)  # 使用LaTeX格式
    plt.ylabel('Steady State Population Size', fontsize=12)
    plt.title('Population Dynamics vs Normalized Selection Strength', fontsize=14)
    plt.legend(fontsize=10, framealpha=0.9)
    plt.grid(True, linestyle='--', alpha=0.3)

    # 优化布局和刻度
    plt.gca().set_facecolor('#f5f5f5')  # 浅灰色背景
    plt.tight_layout()
    plt.show()
    